var destinationURI = 'http://localhost:8888/recommender/';

var bbcURI = 'www.bbc.co.ku/programmes/';

function getProgramInfo(title) {
	var httpRequest = new XMLHttpRequest();
	httpRequest.open('POST', bbcURI, false);
	httpRequest.send(title);
	alert(httpRequest.responseText);
}

function getProgramsList() {
	var clientProfile = '<client-profile>'
			+ '<genre name="Comedy" time="100"/>' + '<prefered-programs>'
			+ '<program id="crid://discovery.us/432341"/>'
			+ '</prefered-programs>' + '</client-profile>';
	var httpRequest = new XMLHttpRequest();
	httpRequest.open('POST', destinationURI, true);
	httpRequest.onreadystatechange = function() {
		if (httpRequest.readyState == 4) {
			var programsList = new Array();
			var parser = new DOMParser();
			var xmlDoc = parser.parseFromString(responseText);
			var programTag = xmlDoc.getElementsByTagName("program");
			for (i = 0;i < programTag.length;i++) {
				programsList[programTag[i].childNodes[0].nodeValue] = programTag[i].getAttribute("uri");
			}
			alert(programsList);
//			alert(httpRequest.responseText);
		}
	}
	httpRequest.send(clientProfile);
}

function getSpecificProgram(crid) {
	var requestData = '<program-info>' + crid + '</program-info>';
	var httpRequest = new XMLHttpRequest();
	httpRequest.open('POST', destinationURI, true);
	httpRequest.onreadystatechange = function() {
		if (httpRequest.readyState == 4) {
			alert(httpRequest.responseText);
		}
	}
	httpRequest.send(requestData);
}